/**
 * 
 */
package com.vsct.maia.auditl;

import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class ConnexionBD {

	private DataSource dataSource;
	private Connection connection;
	private Statement statement;
	public List<String> services = new ArrayList<String>();
	
	public ConnexionBD() {
		
		try {
			// Get DataSource
			InitialContext initContext = new InitialContext();
			if(initContext == null ) throw new Exception("Boom - No Context"); 
				
			this.dataSource = (DataSource) initContext.lookup("java:/comp/env/jdbc/dblogs");
			if (this.dataSource  == null) {
				throw new Exception("Data source not found!");
			}
			
			this. connection = dataSource.getConnection();		
			
			if(connection != null) 
			{
				this.statement = connection.createStatement();

			}else {
				throw new Exception("Connexion echoué\n!");
			}
			
			
		} catch (NamingException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	


	public DataSource getDataSource() {
		return dataSource;
	}


	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}


	public Connection getConnection() {
		return connection;
	}


	public void setConnection(Connection connection) {
		this.connection = connection;
	}


	public Statement getStatement() {
		return statement;
	}


	public void setStatement(Statement statement) {
		this.statement = statement;
	}
	
	
}


	